package com.jgzx.service;

import cn.hutool.core.util.ObjectUtil;
import com.jgzx.common.R;
import com.jgzx.domain.vo.BlogUpdateVO;
import com.jgzx.domain.vo.BlogVO;
import com.jgzx.domain.vo.BlogaddVO;
import com.jgzx.domain.vo.BlogdeleteVO;
import com.jgzx.mapper.BlogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BlogService {
    @Resource
    private BlogMapper blogMapper;
    /**
     * 查询所有博客
     */
    public List<BlogVO> select(){
        return blogMapper.select();
    }
    /**
     * 根据id查询博客
     */
    public BlogVO getInfo(int id){
        return blogMapper.getInfo(id);
    }
    /**
     * 删除博客根据id
     */
    public BlogdeleteVO delete(int id){
        return blogMapper.delete(id);
    }
    /**
     * 新增博客
     */
    public BlogaddVO Add(BlogVO blogVO){
        if(ObjectUtil.isNull(blogVO)){
            R.fail("对象不能为空");
        }
        return blogMapper.Add(blogVO);
    }
    /**
     * 更改博客内容
     */
    public BlogUpdateVO updata(int id, String title, String author, int views){
        return blogMapper.updata(id,title,author,views);
    }
}
